import { defineStore } from 'pinia'
import request from '@/utils/request'
import {BannerItem, IApiRes,GoodItem,HotGoods} from '@/types/data'

export default defineStore('home',{
   state:()=>{
    return{
      bannerList:[] as BannerItem[],
      newGoodList:[] as GoodItem[],
      hotGoodList:[] as HotGoods[]
    }
   },
   actions:{
    async getBannerList(){
      // const res = await request.get<{msg:string,result:BannerItem[]}>('/home/banner')
      const res = await request.get<IApiRes<BannerItem[]>>('/home/banner')
      console.log('轮播图',res)
      this.bannerList = res.data.result
    },
    // 新鲜好物
    async getNewList(){
      const res = await request.get<IApiRes<GoodItem[]>>('/home/new')
      console.log('新鲜好物',res.data.result)
      this.newGoodList=res.data.result
    },
    // 人气推荐
    async getHotList(){
     const res = await request.get<IApiRes<HotGoods[]>>('/home/hot')
     console.log('人气推荐',res.data.result);
     this.hotGoodList=res.data.result
    }
   }
})